/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
 */

package org.apache.ranger.obs.server;

import org.apache.hadoop.conf.Configuration;
import org.junit.AfterClass;
import org.junit.BeforeClass;

import java.util.ArrayList;

/**
 * description
 *
 * @since 2021-10-13
 */
public abstract class DistributedMiniServerBaseTest {
    @BeforeClass
    public static void startMiniServer() throws Exception {
        String principal = "ranger/hadoop@EXAMPLE.COM";
        Configuration server1_conf = new Configuration();
        server1_conf.set("hadoop.security.authentication", "kerberos");
        server1_conf.set("ranger.obs.service.kerberos.principal", principal);
        server1_conf.set("ranger.obs.service.rpc.address", "0.0.0.0:26901");
        server1_conf.set("ranger.obs.service.status.port", "26900");
        server1_conf.set("ranger.obs.service.dt.secret.provider",
            "org.apache.ranger.obs.security.token.MockSecretProvider");
        server1_conf.set("ranger.obs.service.authorizer", "org.apache.ranger.obs.authorize.MockAuthorizer");

        Configuration server2_conf = new Configuration();
        server2_conf.set("hadoop.security.authentication", "kerberos");
        server2_conf.set("ranger.obs.service.kerberos.principal", principal);
        server2_conf.set("ranger.obs.service.rpc.address", "0.0.0.0:26902");
        server2_conf.set("ranger.obs.service.status.port", "26899");
        server2_conf.set("ranger.obs.service.dt.secret.provider",
            "org.apache.ranger.obs.security.token.MockSecretProvider");
        server2_conf.set("ranger.obs.service.authorizer", "org.apache.ranger.obs.authorize.MockAuthorizer");

        ArrayList<Configuration> configurations = new ArrayList<>();
        configurations.add(server1_conf);
        configurations.add(server2_conf);

        MiniServerUtil.startDistributedMiniServer(configurations, principal);
    }

    @AfterClass
    public static void stopMiniServer() {
        MiniServerUtil.stopDistributedMiniServer();
    }
}
